/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistencia;

import beans.Usuario;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author TalesHugo
 */
public class Persistencia {

    public void gravaObjetoArquivo(Map<String, Usuario> users) throws IOException {
        ObjectOutputStream out = null;
        try {
            out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("persistencia")));
            out.writeObject(users);
        } finally {
            out.close();
        }
    }

    public Map lerObjetoArquivo() throws IOException, ClassNotFoundException {
        Map<String, Usuario> users = new HashMap<String, Usuario>();
        ObjectInputStream in = null;
        try {
            in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("persistencia")));
            users = (Map<String, Usuario>) in.readObject();
            return users;
        } finally {
            in.close();
        }
    }
}
